<?php
/**
 * Created by PhpStorm.
 * 地区处理
 * User: caicm
 * Date: 2017/6/28
 * Time: 20:31
 */

namespace WMApi\Service;
use WMApi\Model\RegionModel;

class RegionService {

    /**
     * 获取区域列表
     * Created By caicm
     * @return mixed
     */
    public function get_region_list(){
        $region_list = S('wm_region_list');
        if(!$region_list){
            $region_model = new RegionModel();
            $region_list = $region_model->get_region_list(1);
            foreach ($region_list as $key=>$value){
                $region_list[$key]['region_list'] = $region_model->get_region_list($value['region_id']);
                foreach ($region_list[$key]['region_list'] as $k=>$v){
                    $region_list[$key]['region_list'][$k]['region_list'] = $region_model->get_region_list($v['region_id']);
                }
            }
            S('wm_region_list', $region_list, 0);
        }
        return $region_list;
    }

    /**
     * 获取地区地址信息
     * Created By caicm
     * @param int $province_id
     * @param int $city_id
     * @param int $district_id
     * @return mixed
     */
    public function get_address_data($province_id=0, $city_id=0, $district_id=0){
        $region_model = new RegionModel();
        $region_info = $region_model->get_region_info($district_id);
        if($region_info['province'] == $province_id && $region_info['city'] == $city_id && $region_info['district'] == $district_id){
            return $region_info;
        }else{
            returnApiError('地区参数有误');
        }
    }

}